import {Application} from 'egg';

export default (app: Application) => {
    const {controller, router} = app;

    const URL_PREFIX = '/api/v1';

    // 通过微信code登录 *
    router.post(`${URL_PREFIX}/login/`, controller.login.login);
    // 发送短信 *
    router.post(`${URL_PREFIX}/bind-phone/sms/`, controller.bindPhone.sendSms);
    // 绑定手机号
    router.post(`${URL_PREFIX}/bind-phone/`, controller.bindPhone.bindPhone);

    // 获取老师排课计划 *
    router.get(`${URL_PREFIX}/teacher-schedule/`, controller.teacherSchedule.getTeacherSchedules);
    // 老师更新排课计划 *
    router.put(`${URL_PREFIX}/teacher-schedule/`, controller.teacherSchedule.updateTeacherSchedules);

    // 获取排课安排 *
    router.get(`${URL_PREFIX}/ordered-schedule/`, controller.orderedSchedule.getOrderedSchedules);

    // 获取请假申请 *
    router.get(`${URL_PREFIX}/req-update-order/`, controller.reqUpdateOrder.getNeedConfirmReqUpdateOrder);
    // 学生申请请假 *
    router.post(`${URL_PREFIX}/req-update-order/`, controller.reqUpdateOrder.updateOrderedOrder);
    // 老师确认请假
    router.put(`${URL_PREFIX}/req-update-order/`, controller.reqUpdateOrder.confirmReqUpdateOrder);

    // 签到
    router.post(`${URL_PREFIX}/clock/`, controller.clock.clock);

    const URL_ADMIN_PREFIX = '/api/v1/admin';
    const admin = controller.admin;
    // 管理员登录
    router.post(`${URL_ADMIN_PREFIX}/login/`, admin.login.login);
    // 获取用户列表
    router.get(`${URL_ADMIN_PREFIX}/user/:role/:page/`, admin.user.getUsers);
    router.get(`${URL_ADMIN_PREFIX}/user-info/:userId`, admin.user.getUserById);
    // 添加用户
    router.post(`${URL_ADMIN_PREFIX}/user/`, admin.user.addUser);
    // 更新用户状态
    router.post(`${URL_ADMIN_PREFIX}/user/update/`, admin.user.updateUser);
    // 删除用户
    router.post(`${URL_ADMIN_PREFIX}/user/delete/`, admin.user.deleteUser);
    // 搜索学生
    router.post(`${URL_ADMIN_PREFIX}/user/search/:role/`, admin.user.search);
    router.post(`${URL_ADMIN_PREFIX}/user/search/`, admin.user.search);

    // 获取指定老师的排课计划
    router.post(`${URL_ADMIN_PREFIX}/get-teacher-schedule/`, admin.teacherSchedule.getTeacherSchedules);
    router.get(`${URL_ADMIN_PREFIX}/ordered-schedule/teacher/:id/:page/`, admin.orderedSchedule.getByTeacher);
    router.get(`${URL_ADMIN_PREFIX}/ordered-schedule/student/:id/:page/`, admin.orderedSchedule.getByStudent);
    router.post(`${URL_ADMIN_PREFIX}/get-ordered-schedule/`, admin.orderedSchedule.getByDate);

    // 查看所有排课
    router.get(`${URL_ADMIN_PREFIX}/ordered-schedule/:page/:orderBy/`, admin.orderedSchedule.get);
    router.post(`${URL_ADMIN_PREFIX}/ordered-schedule/`, admin.orderedSchedule.addByTimes);
    router.post(`${URL_ADMIN_PREFIX}/ordered-schedule/update/`, admin.orderedSchedule.updateOne);
    router.post(`${URL_ADMIN_PREFIX}/ordered-schedule/delete/`, admin.orderedSchedule.deleteAll);

    // 管理员消息
    router.get(`${URL_ADMIN_PREFIX}/msg/:page/`, controller.admin.msg.getAllMsg);
    router.post(`${URL_ADMIN_PREFIX}/msg/update/`, controller.admin.msg.readMsg);
    router.post(`${URL_ADMIN_PREFIX}/msg/delete/`, controller.admin.msg.deleteMsg);
};
